package chainOfResponsibility;

/**
 * 抽象处理类
 */
public abstract class Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    // 领导处理请求
    private int numStart;
    private int numEnd;

    // 声明后续者（声明上级领导）
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 各级领导审批的方法
    public abstract void handleLeave(LeaveRequest leaveRequest);

    // 该领导提交审批
    public final void submit(LeaveRequest leaveRequest){
        this.handleLeave(leaveRequest);
        if (this.nextHandler != null && leaveRequest.getNum() > this.numEnd) {
            this.nextHandler.submit(leaveRequest);
        } else {
            System.out.println("流程结束");
        }


    }

}